var cur_page = 1;
var resArry = [];
var app = angular.module("newApp", []);
var nomore = false;
app.controller("contentController", function($scope, $http) {
	$scope.initView = function() {
		if(nomore){return;}
		plus.nativeUI.showWaiting('加载中...');
		$http({
			method: 'post',
			url: apiRoot,
			data: {
				action: 'Community.more',
				cid: cid,
				hot: new_hot,
				page: cur_page
			}
		}).then(function successCallback(response) {
			plus.nativeUI.closeWaiting();
			if(response.data.data.note.length == 0){
				$scope.not_more  = 1;
				nomore = true;
				return;
			}
			resArry.push(response.data.data.note);
			$scope.notes = resArry; //最新内容数据 
		}, function errorfunction(e) {
			console.log(e);
			plus.nativeUI.closeWaiting();
		})
	}

	$scope.openNoteDetail = function(uid, type, id) {
		plus.webview.create('view_detail.html', 'view_detail.html',{},{noteUid:uid,type:type,noteId:id}).show('pop-in');
	}
})

var ws, cid, new_hot;
document.addEventListener("plusready", function() {
	ws = plus.webview.currentWebview();
	appElement = document.querySelector('[ng-controller=contentController]');
	$scope = angular.element(appElement).scope();
	cid = ws.cid;
	new_hot = ws.is_hot //是最新内容或是最热门内容
	if(new_hot == 1) {
		$('.mui-title').html('热门内容');
	} else {		
		$('.mui-title').html('最新内容');
	}
	$scope.initView();
	$scope.$apply();

})